package com.mall.admin.service;

import cn.hutool.core.collection.CollUtil;
import com.mall.commons.utils.R;
import com.mall.domain.UmsResource;
import com.mall.domain.UmsResourceCategory;
import com.mall.interface1.api.UmsResourceApi;
import com.mall.interface1.api.UmsResourceCategoryApi;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UmsResourceCategoryService {
    @DubboReference
    private UmsResourceCategoryApi umsResourceCategoryApi;
    @DubboReference
    private UmsResourceApi umsResourceApi;
    public R create(UmsResourceCategory umsResourceCategory) {
        umsResourceCategoryApi.save(umsResourceCategory);
        return R.success("",null);
    }

    public R delete(Integer id) {
        List<UmsResource> umsResource=umsResourceApi.selectCateId(id);
        if(CollUtil.isEmpty(umsResource)){
            umsResourceCategoryApi.delete(id);
        }else{
            List<Long> ids = CollUtil.getFieldValues(umsResource, "id", Long.class);
            umsResourceApi.deleteIds(ids);
            umsResourceCategoryApi.delete(id);
        }
        return R.success("",null);
    }
     public R listAll() {
      List<UmsResourceCategory> list= umsResourceCategoryApi.listAll();
        return R.success("",list);
    }

    public R update(UmsResourceCategory umsResourceCategory) {
        umsResourceCategoryApi.update(umsResourceCategory);
        return R.success("",null);
    }
}
